package com.link.base.base.policy.controller;


import com.link.base.base.policy.model.PcyAttribute;
import com.link.base.base.policy.service.PcyAttributeService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.service.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author huanglongjian
 * @Comments 销售政策 客户属性范围
 */
@Controller
@RequestMapping("/link/pcyAttribute")
public class PcyAttributeController extends BasicController<PcyAttribute> {

    @Resource
    private PcyAttributeService pcyAttributeService;

    @Override
    public BasicService<PcyAttribute> getBasicService() throws Exception {
        return pcyAttributeService;
    }

    /**
     * @param pcyAttribute
     * @return
     * @Comments 通过政策id 查询客户属性
     */
    @RequestMapping("/queryAttrByPcyId")
    public Map<String, Object> queryAttrByPcyId(@RequestBody PcyAttribute pcyAttribute) {
        //前端调用的时候，需要添加一级类型（值列表类型）。
        //基于不同的类型，返回不同的属性集，包括客户类型（包括子类型），
        //客户级别，客户阶段
        //当传入为客户类型的时候，会返回给前端客户类型加上客户子类型的集合
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            if (pcyAttribute.getPcyId() == null) {
                throw new ServiceException("POLICY-001");
            }
            List<PcyAttribute> pcyAttributeList = pcyAttributeService.queryAttrByPcyId(pcyAttribute);
            result.put("success", true);
            result.put("result", pcyAttributeList);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
